/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author            Notes
 * 2020-05-28     Ghazi          the first version
 */
#include <rtthread.h>
#include <board.h>
#include <dfs_fs.h>

#if defined(RT_USING_W25QXX) || defined(RT_USING_SFUD)
    #include <drv_spi.h>
#ifdef RT_USING_W25QXX
    #include "spi_flash_w25qxx.h"
#elif defined(RT_USING_SFUD)
    #include "string.h"
    #include "spi_flash.h"
    #include "spi_flash_sfud.h"
    sfud_flash sfud_spiflash;
    rt_spi_flash_device_t spi_device;
#endif

int rt_spi_flash_init(void)
{
    rt_hw_spi_device_attach("spi2", "w25q64", GPIOC, GPIO_PIN_0);
#ifdef RT_USING_W25QXX
    return w25qxx_init("spiflash", "w25q64");
#elif defined(RT_USING_SFUD)
    spi_device = rt_sfud_flash_probe("spiflash", "w25q64");
    if (spi_device == RT_NULL)
    {
        return -RT_ERROR;
    }
    memcpy(&sfud_spiflash, spi_device->user_data, sizeof(sfud_flash));
    return 0;
#endif
}
INIT_PREV_EXPORT(rt_spi_flash_init);

#endif
